package net.cl.support.struts;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.cl.mvc.pagination.Pageable;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;

/**
 * 所有<b>struts2</b>的action类可以继承本类
 * 
 * @author CaoLei
 */
public class BaseAction implements Action {

	protected Pageable pageList;

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

	protected HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	protected HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	protected void write(String s) {
		PrintWriter writer = null;
		try {
			writer = getResponse().getWriter();
			writer.print(s);
			writer.flush();
		} catch (IOException e) {
			// e.printStackTrace();
		} finally {
			if (writer != null)
				writer.close();
		}
	}

	public void setPageList(Pageable pageList) {
		this.pageList = pageList;
	}

	public Pageable getPageList() {
		return pageList;
	}

}
